﻿Imports System.Collections.Generic

Partial Class WebForm_ManageDownload_SearchRoleControl
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Event OK_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        RaiseEvent OK_Click(Me, New EventArgs)
    End Sub

    Protected Sub GridView_Volunteers_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView_Volunteers.PageIndexChanged
        Me.mpSearch.Show()
    End Sub

    Protected Sub GridView_Volunteers_Sorted(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView_Volunteers.Sorted
        Me.mpSearch.Show()
    End Sub

    Protected Sub CheckBoxAll_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim MyChecked As Boolean = TryCast(sender, CheckBox).Checked

        For Each MyGridViewRow As GridViewRow In GridView_Volunteers.Rows

            TryCast(MyGridViewRow.FindControl("CheckBox1"), CheckBox).Checked = MyChecked

        Next
        Me.mpSearch.Show()
    End Sub

End Class

Partial Class WebForm_ManageDownload_SearchRoleControl

    Public Sub InitDataAndShow(ByVal strFileSaveName As String)

        ObjectDataSource1.SelectParameters("FileSaveName").DefaultValue = strFileSaveName
        GridView_Volunteers.PageIndex = 0
        GridView_Volunteers.DataSourceID = ObjectDataSource1.ID
        GridView_Volunteers.DataBind()

        Me.mpSearch.Show()

    End Sub

    Public ReadOnly Property SelectedValues() As List(Of String)
        Get
            Dim Volunteers As New List(Of String)

            For Each row As GridViewRow In Me.GridView_Volunteers.Rows
                Dim key As DataKey = Me.GridView_Volunteers.DataKeys(row.RowIndex)

                If TryCast(row.FindControl("CheckBox1"), CheckBox).Checked = True Then
                    Volunteers.Add(key("RoleID"))
                End If
            Next

            Return Volunteers
        End Get
    End Property

End Class
